package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.mapper.CategoryMapper;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 菜品及套餐分类 服务实现类
 * </p>
 *
 * @author wang
 * @since 2023-07-06
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        Page<Category> categoryPage = new Page<>(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());
        Page<Category> pageQuery = categoryMapper.pageQuery(categoryPage,categoryPageQueryDTO);
        PageResult pageResult = new PageResult();
        pageResult.setTotal(pageQuery.getTotal());
        pageResult.setRecords(pageQuery.getRecords());
        return pageResult;
    }


    @Override
    public void startOrStop(Integer status, Long id) {
        LambdaUpdateWrapper<Category> categoryLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        categoryLambdaUpdateWrapper.eq(Category::getId,id).set(Category::getStatus,status);
        this.update(categoryLambdaUpdateWrapper);
    }
}
